<!-- 提现 -->
<template>
	<view class="u-m-50">
		<view class="u-m-t-60">
			<view class="u-font-24">提现金额</view>
			<view class="u-flex u-m-t-20 u-p-b-10 input-box">
				<u-icon name="money" custom-prefix="master" size="20"></u-icon>
				<u-input class="u-flex-1 u-m-l-10" border="none" v-model="value" type="digit" placeholder="请输入提现金额" @blur="inputMoney" :clearable="false" />
			</view>
			<view class="u-m-t-10 u-m-b-20 m-c-o" v-if="chao">输入金额超出零钱金额</view>
			<view class="u-m-t-10 u-m-b-20" v-else>
				当前零钱余额￥{{ val }}，
				<text class="m-c-b" @click="value = val">全部提现</text>
			</view>
			<view class="u-m-t-30 u-m-b-30">
				<view class="m-btn-g m-b-ro-20" style="letter-spacing: 4rpx;" v-if="withdrawalStatus">不足100，不能提现！</view>
				<view class="m-btn-g m-b-ro-20" v-else-if="value > val">确认</view>
				<view class="m-btn m-b-ro-20" v-else @click="withdrawalOk">确认</view>
			</view>
			<view class="m-c-h">
				<view class="withdrawal-title u-font-">规则说明</view>
				<view class="u-m-t-20">
					1. 按提现金额的
					<text class="m-c-b">0.6%</text>
					收取服务费。
				</view>
				<view class="u-m-t-20">
					2. 一般
					<text class="m-c-b">1~3</text>
					个工作日内到账（如遇到高峰，到账时间会延长）。
				</view>
				<view class="u-m-t-20">3. 我们可在法律法规允许的范围内对本次活动规则解释并作出适当修改。</view>
			</view>
		</view>
	</view>
</template>
<script>
export default {
	data() {
		return {
			val: 0,
			value: '',
			withdrawalStatus: false,
			show: false
		};
	},
	computed: {
		chao() {
			return this.accSub(this.value, this.val) > 0;
		}
	},
	onLoad(e) {
		// #ifdef MP-WEIXIN
		uni.hideShareMenu();
		// #endif
		if (e.val) {
			this.val = +e.val;
		}
		if (this.val < 100) {
			this.withdrawalStatus = true;
		}
	},
	methods: {
		acc(card) {
			return card.substring(card.length - 4);
		},
		//输入金额
		inputMoney(e) {
			const exp = /^([1-9][0-9]*)+(\.[0-9]{1,2})?$/;
			if (!exp.test(e)) {
				this.$u.toast('请输入正确的金额');
				this.value = '';
			} else {
				this.value = parseFloat(e).toFixed(2);
			}
		},
		async withdrawalOk() {
			if (!this.value) {
				this.$u.toast('请输入提现金额！');
				return;
			} else if (+this.value < 100) {
				this.$u.toast('不足100，不能提现！');
				return;
			} else if (this.value > this.val) {
				this.$u.toast('提现金额不能大于零钱余额！');
				return;
			} else {
				let txmoney = await this.require('getWithdr', { money: this.value });
				if (txmoney) {
					this.$u.toast('申请提现成功！');
				}
			}
		}
	}
};
</script>
<style lang="scss" scoped>
.input-box {
	border-bottom: 2rpx solid #ededed;
}
.withdrawal-title {
	line-height: 80rpx;
	font-weight: bold;
}
</style>
<style>
	page {
		background-color: #fff;
	}
</style>